﻿using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using TomNet.FreeSql.Base;

namespace TomNet.Demo.Entity.Entities
{
    //=========== one to one ===========//

    // 用户表
    public class User
    {
        // Id、UserId、User_id
        public int Id { get; set; }
        public string Name { get; set; }
        public UserExt UserExt { get; set; }
    }

    // 用户扩展信息表  
    public class UserExt
    {
        // Id、UserId、User_id、UserExtId、UserExt_id
        public int Id { get; set; }
        //public int UserId { get; set; } 
        public string NickName { get; set; }
        public User User { get; set; }
    }


    //=========== one to many || many to one ===========//

    [Description("部门表")]
    [Table(Name = "Department")]
    public class DepartmentEntity : EntityLongBase
    {
        public string Name { get; set; }
        public virtual List<EmployeeEntity> Employees { get; set; }
    }

    [Description("员工表")]
    [Table(Name = "Employee")]
    public class EmployeeEntity : EntityLongBase
    {
        public string Name { get; set; }

        public long DepartmentId { get; set; }
        public DepartmentEntity Department { get; set; }
    }

    //=========== many to many ===========//
    [Description("歌曲表")]
    [Table(Name = "Song")]
    public class SongEntity : EntityLongBase
    {
        public string Name { get; set; }
        [Navigate(ManyToMany = typeof(SongTagEntity))]
        public virtual List<TagEntity> Tags { get; set; }
    }

    [Description("标签表")]
    [Table(Name = "Tag")]
    public class TagEntity : EntityLongBase
    {
        public string Name { get; set; }

        [Navigate(ManyToMany = typeof(SongTagEntity))]
        public virtual List<SongEntity> Songs { get; set; }
    }


    [Description("歌曲与标签")]
    [Table(Name = "SongTag")]
    public class SongTagEntity : EntityLongBase
    {
        public long SongId { get; set; }
        [Navigate(nameof(SongId))]
        public virtual SongEntity Song { get; set; }

        public long TagId { get; set; }
        [Navigate(nameof(TagId))]
        public virtual TagEntity Tag { get; set; }
    }

    //=========== tooooooo many ===========//
    public class TableA : EntityLongBase
    {
        public string Name { get; set; }
        public virtual List<TableB> TableB { get; set; }
        public virtual List<TableC> TableC { get; set; }
    }

    public class TableB : EntityLongBase
    {
        public string Name { get; set; }
        public long TableAId { get; set; }
        public TableA TableA { get; set; }
    }

    public class TableC : EntityLongBase
    {
        public string Name { get; set; }

        public long TableAId { get; set; }
        public TableA TableA { get; set; }

        public virtual List<TableD> TableD { get; set; }
    }

    public class TableD : EntityLongBase
    {
        public string Name { get; set; }
        public long TableCId { get; set; }
        public TableC TableC { get; set; }
        public virtual List<TableE> TableE { get; set; }
    }

    public class TableE : EntityLongBase
    {
        public string Name { get; set; }
        public long TableDId { get; set; }
        public TableD TableD { get; set; }
    }


    //=========== tree(parent and son) ===========//

    [Description("地区表")]
    [Table(Name = "Area")]
    public class AreaEntity : EntityLongBase
    {
        public string Name { get; set; }
        public string Code { get; set; }
        public long ParentId { get; set; }

        [Navigate(nameof(ParentId))]
        public AreaEntity Parent { get; set; }
        [Navigate(nameof(ParentId))]
        public List<AreaEntity> Childs { get; set; }
    }
}
